<template>
	<view class="reg-block">

		<form @submit="regOrLogin">
			<view class="avatar-wapper">
				<image class="reg-avatar" src="../../static/tabbar/my_selected.png" mode=""></image>
			</view>

			<view class="info-wapper">
				<label class="reg-lbl">账号</label>
				<input name="username" type="text" value="" class="input" placeholder="请输入用户账号" placeholder-class="graywords" />
			</view>
			
			<view class="info-wapper">
				<label class="reg-lbl">密码</label>
				<input name="userpwd" type="text" password="true" class="input" value="" placeholder="请输入用户密码" placeholder-class="graywords" />
			</view>

			<button form-type="submit" class="reg-btn" type="primary" >注册/登录</button>
		</form>
		
		<!-- #ifndef H5 -->
		
		<!-- #endif -->
		<!-- #ifdef MP -->
		<button type="default" open-type="getUserInfo" @getuserinfo="wxLogin">微信登录</button>
		<!-- #endif -->
		
	</view>
</template>

<script>
	export default {
		data() {
			return {

			}
		},
		methods: {
			regOrLogin(e){
				var { username,userpwd } = e.detail.value;
				
				if(username=="admin" && userpwd=="888"){
					uni.setStorageSync("gUser",{
						username:"admin",
						avatar: "https://img2.baidu.com/it/u=3947572783,1476163811&fm=26&fmt=auto&gp=0.jpg",
						birthday:"2021-05-28",
						sex: 1 
					});
					uni.switchTab({
						url:"../me/me"
					})
				}else {
					uni.setStorageSync('gUser',null);
					uni.showToast({
						title:"用户名或密码错误..."
					})
				}
			},
			wxLogin(e){
				console.log(e)
				e.detail.userInfo;
				
				uni.login({
					provider:"weixin",
					success(res) {
						console.log(res)
						
						// TODO http 后台，入参code
						
					}
				})
				
			}
		}
	}
</script>

<style>
	@import url("regLogin.css");
</style>
